/**
 * Created by 余保林 on 2017/8/14.
 */
import ajax from '../ajax'

export default {
  getRoleList (success, fail = null) {
    ajax.get({
      url: `/api/role/roleList`,
      success,
      fail
    })
  },
  saveRole (roleData, success, fail = null) {
    const method = roleData.id === 0 ? 'post' : 'put'
    ajax[method]({url: `/api/role/${roleData.id}`, data: roleData, success, fail})
  },
  deleteRole (roleId, success) {
    ajax.del({url: `/api/role/${roleId}`, success})
  },
  deleteRoleList (roleIds, success) {
    ajax.del({url: '/api/role/deleteList', data: roleIds, success})
  },
  getRoleUser (roleId, success, fail = null) {
    ajax.get({
      url: `/api/role/user?roleId=${roleId}`,
      success,
      fail
    })
  },
  saveRoleUser (roleId, userIds, success, fail = null) {
    ajax.post({url: `/api/role/addUser`, data: {roleId: roleId, userIds: userIds}, success, fail})
  },
  deleteRoleUser (roleId, userIds, success, fail = null) {
    ajax.del({url: `/api/role/deleteUser`, data: {roleId: roleId, userIds: userIds}, success, fail})
  },

  saveRoleMenu (roleId, menuIds, success, fail = null) {
    ajax.post({url: `/api/role/saveMenu`, data: {roleId, menuIds}, success, fail})
  },
  deleteRoleMenu (roleId, success, fail = null) {
    ajax.del({url: `/api/role/deleteMenu`, data: {roleId}, success, fail})
  }
}

